#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int partition(vector<int>& arr, int low, int high){
    int pivot = arr[high];
    int i = low - 1;
    // 遍历数组，将小于基准的元素放到左侧区域
    for(int j = low; j <= high - 1; ++j){
        if(arr[j] <= pivot){
            ++i;
            swap(arr[i], arr[j]);
        }
    }
    swap(arr[i + 1], arr[high]);
    return i + 1;
}

void quickSort(vector<int>& arr, int low, int high){
    if(low < high){
        int pi = partition(arr, low, high);
        quickSort(arr, low, pi - 1);
        quickSort(arr, pi + 1, high);
    }
}

int main(){
    vector<int> arr = {3,1,4,5,6,7,9,0};
    quickSort(arr, 0, arr.size() - 1);
    for(int x : arr) cout << x << " ";
    return 0; 
}